package com.xlh.enums;

import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.collections.CollectionUtils;

import java.util.List;
import java.util.Objects;

/**
 * 系统配置枚举
 * <p>
 * Created by lx on 2019/1/28.
 */
@Getter
@NoArgsConstructor
@AllArgsConstructor
public enum SystemConfigEnum {

    COURSE_ICON("courseIcon", "课程默认图标") {
        @Override
        public String getMappingUrl(String name) {
            return LocalResourcesEnum.SYSTEM_FILE.getMappingUrl(name);
        }
    },
    PROJECT_NAME("projectName", "项目名"),
    UNAUTHORIZED_LOGO_IMAGE("unauthorizedLogoImage", "未授权logo图片") {
        @Override
        public String getMappingUrl(String name) {
            return LocalResourcesEnum.SYSTEM_FILE.getMappingUrl(name);
        }
    },
    COPYRIGHT_ATTRIBUTION("copyrightAttribution", "版权所有"),
    PHONE_NUMBER("phoneNumber", "联系电话"),
    ADDRESS("address", "地址"),
    INNER_LOGO_IMAGE("innerLogoImage", "内页logo图片") {
        @Override
        public String getMappingUrl(String name) {
            return LocalResourcesEnum.SYSTEM_FILE.getMappingUrl(name);
        }
    },
    UNAUTHORIZED_DATA_NAME("unauthorizedDataName", "未授权页面数据名"),
    INDEX_QR_CODE("indexQrCode", "首页二维码"),
    FEEDBACK_QR_CODE("feedbackQrCode", "问题反馈二维码"),
    UNAUTHORIZED_DATA_INTRODUCTION("unauthorizedDataIntroduction", "未授权页面简介"),
    TECHNOLOGY_ICON("technologyIcon", "技能图标") {
        @Override
        public String getMappingUrl(String name) {
            return LocalResourcesEnum.SYSTEM_FILE.getMappingUrl(name);
        }
    },
    USER_ICON("userIcon", "用户头像") {
        @Override
        public String getMappingUrl(String name) {
            return LocalResourcesEnum.SYSTEM_FILE.getMappingUrl(name);
        }
    },
    INVITATION_CODE("invitationCode", "申请码"),
    INVITATION_ACCESS_IP("invitationAccessIP", "申请码访问ip"),
    INDEX_URL("indexUrl", "前端首页请求地址"),
    CASE_ICON("caseIcon", "行业图标") {
        @Override
        public String getMappingUrl(String name) {
            return LocalResourcesEnum.CASES.getMappingUrl(name);
        }
    },
    CASE_ICON_DEFAULT("case", "案例图标") {
        @Override
        public String getMappingUrl(String name) {
            return LocalResourcesEnum.CASES.getMappingUrl(name);
        }
    },
    IMAGE_ICON("image_icon", "镜像图标") {
        @Override
        public String getMappingUrl(String name) {
            return LocalResourcesEnum.SYSTEM_FILE.getMappingUrl(name);
        }
    },
    TRAINING_ICON("training_icon", "实训图标") {
        @Override
        public String getMappingUrl(String name) {
            return LocalResourcesEnum.SYSTEM_FILE.getMappingUrl(name);
        }
    },
    BROWSER_VERSION("browserVersion", "浏览器版本") {
        @Override
        public String getMappingUrl(String name) {
            return LocalResourcesEnum.SYSTEM_FILE.getMappingUrl(name);
        }
    },
    SKILL_ICON("skill_icon", "岗位图标") {
        @Override
        public String getMappingUrl(String name) {
            return LocalResourcesEnum.SYSTEM_FILE.getMappingUrl(name);
        }
    },
    SCHOOL_TYPE("schoolType", "本科、专科"),
    INDEX_SKILL("indexSkill", "首页技能是否显示 1：显示 0：隐藏"),
    COURSE_SYSTEM_SHOW("courseSystemShow", "课程体系是否显示 1： 显示 0：隐藏"),
    BUSINESS_SHOW("businessShow", "案例库是否显示 1： 显示 0：隐藏"),
    TECHNOLOGY_SHOW("technologyShow", "技术库是否显示 1： 显示 0：隐藏"),

    VERSION("version", "版本号");

    private String key;

    private String value;

    public String getMappingUrl(String name) {
        return null;
    }

    public static SystemConfigEnum getByKey(String Key) {
        for (SystemConfigEnum systemConfigEnum : SystemConfigEnum.values()) {
            if (Objects.equals(systemConfigEnum.getKey(), Key)) {
                return systemConfigEnum;
            }
        }
        return null;
    }

    public static String getValueByKey(String key) {
        SystemConfigEnum systemConfigEnum = getByKey(key);
        return systemConfigEnum == null ? null : systemConfigEnum.getValue();
    }

    public static List<String> filterKeys(List<String> keys) {

        if (CollectionUtils.isEmpty(keys)) return Lists.newArrayList();

        List<String> result = Lists.newArrayList();
        for (SystemConfigEnum configEnum : SystemConfigEnum.values()) {
            if (keys.contains(configEnum.getKey())) {
                result.add(configEnum.getKey());
            }
        }
        return result;

    }

}
